package controller;

import bean.DonorsMaterial;
import bean.PublicWelfareDonation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import service.Article_Management_Service;
import service.DonationService;
import util.ResponseBean;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class Donation {

    @Resource
    private DonationService donationService;

    @Resource
    private Article_Management_Service article_management_service;

    @Resource
    private ResponseBean responseBean;

    @GetMapping("allarticle")
    @ResponseBody
    public ResponseBean test1(){
        List<PublicWelfareDonation> P=article_management_service.all();
        responseBean.setAll(200,"bzd",P);
        return responseBean;

    }

    @PostMapping("add")
    @ResponseBody
    public ResponseBean add(@RequestBody DonorsMaterial donorsMaterial){
        int i = donationService.Add_Donors(donorsMaterial);
        if (i!=0){
            responseBean.setAll(200,"success",null);
            return responseBean;
        }else {
            responseBean.setAll(205,"erroe",null);
            return responseBean;
        }
    }
}
